<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function array(envelopes) {
      var arr = envelopes
      var dp = []
      for (var i = 0; i < envelopes.length; i++) dp.push(1)
      arr.sort(function (a, b) { return a[0] - b[0] })
      for (var i = 0; i < arr.length; i++) {
        for (var j = 0; j < i; j++) {
          if (arr[j][1] < arr[i][1] && arr[j][0] !== arr[i][0]) {
            dp[i] = Math.max(dp[i], dp[j] + 1)
          }
        }
      }
      return Math.max(...dp)
    };
    console.log(array([[5, 4], [6, 4], [6, 7], [2, 3]]));
  </script>
</body>

</html>